package com.example.bms.util;

import com.example.bms.entity.ApiResult;


/**
 * @apiNote 用于封装返回的结果集
 * @author 钟顺浩
 * @email 2918185121@qq.com
 * @since 1.0.0
 */
public class ApiResultHandler {


    /**
     * @apiNote 用于封装返回的结果集
     * @param object 结果集对象
     * @author 钟顺浩
     * @email 2918185121@qq.com
     * @return ApiResult
     * @since 1.0.0
     */
    public static ApiResult success(Object object) {
        ApiResult apiResult = new ApiResult();
        apiResult.setData(object);
        apiResult.setCode(200);
        apiResult.setMessage("请求成功");
        return apiResult;
    }


    /**
     * @apiNote 用于封装返回的结果集
     * @author 钟顺浩
     * @email 2918185121@qq.com
     * @return ApiResult
     * @since 1.0.0
     */
    public static ApiResult success() {
        return success(null);
    }


    /**
     * @apiNote 用于封裝返回的结果集
     * @param code 状态码
     * @param message 提示消息
     * @param data 数据对象
     * @author 钟顺浩
     * @email 2918185121@qq.com
     * @return ApiResult
     * @since 1.0.0
     */
    public static <T> ApiResult buildApiResult(Integer code, String message, T data) {
        ApiResult apiResult = new ApiResult();
        apiResult.setCode(code);
        apiResult.setMessage(message);
        apiResult.setData(data);
        return apiResult;
    }
}
